<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="文章标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入文章标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="所属部门" prop="dept">
        <treeselect style="width: 240px" v-model="queryParams.dept" :options="deptOptions" :show-count="true" placeholder="请选择所属部门" clearable />
      </el-form-item>
      <el-form-item label="一级分类" prop="articleOneClass">
        <el-select v-model="queryParams.articleOneClass" placeholder="请选择一级分类" clearable @change="handleOneClassChange">
          <el-option
            v-for="menu in retirementMenuList"
            :key="menu.id"
            :label="menu.name"
            :value="menu.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" prop="articleTwoClass">
        <el-select v-model="queryParams.articleTwoClass" placeholder="请选择二级分类" clearable>
          <el-option
            v-for="classTwo in retirementClassTwoList"
            :key="classTwo.id"
            :label="classTwo.name"
            :value="classTwo.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="文章类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择文章类型" clearable @change="handleQueryTypeChange">
          <el-option
            v-for="dict in dict.type.article_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="文章状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择文章状态" clearable>
          <el-option
            v-for="dict in dict.type.article_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['retirement:retirementArticlePublished:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['retirement:retirementArticlePublished:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['retirement:retirementArticlePublished:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['retirement:retirementArticlePublished:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table ref="table" v-loading="loading" :data="retirementArticlePublishedList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="文章标题" align="center" prop="title">
        <template slot-scope="scope">
          <div class="text-truncate" :title="scope.row.title" @click="showContentDialog('文章标题', scope.row.title)">
            {{ scope.row.title }}
          </div>
        </template>
      </el-table-column>>
<!--      <el-table-column label="文章内容富文本" align="center" prop="desc" />-->
      <el-table-column label="所属部门" align="center" prop="deptName" />
      <el-table-column label="所属一级分类" align="center" prop="articleOneClassName" />
      <el-table-column label="所属二级分类" align="center" prop="articleTwoClassName" />
      <el-table-column label="文章类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.article_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="文章封面图" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="是否置顶" align="center" prop="isTop" >
        <template slot-scope="scope">
          <span>{{ scope.row.isTop === '1' ? '是' : '否' }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="文号" align="center" prop="policyCode" />
      <el-table-column label="发文地址" align="center" prop="location" />
      <el-table-column label="发文机构" align="center" prop="source" />-->
      <!--   0草稿 1审核中 2驳回 3已发布    -->
      <el-table-column label="文章状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.article_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="发布时间" align="center" prop="date" />
<!--      <el-table-column label="驳回原因" align="center" prop="reason" />-->
      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <div class="action-buttons">
            <!-- 主要操作按钮 -->
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-view"
              @click="handlePreview(scope.row)"
              class="action-btn primary-btn"
            >预览</el-button>

            <!-- 下拉菜单包含其他操作 -->
            <el-dropdown @command="(command) => handleActionCommand(command, scope.row)" trigger="click">
              <el-button size="mini" type="text" class="action-btn dropdown-btn">
                更多操作<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  command="stick"
                  icon="el-icon-upload2"
                  v-hasPermi="['retirement:retirementArticlePublished:remove']"
                >
                  {{ scope.row.isTop === '1' ? '取消置顶' : '置顶' }}
                </el-dropdown-item>
                <el-dropdown-item
                  command="collect"
                  icon="el-icon-star-off"
                >
                  收藏列表
                </el-dropdown-item>

                <el-dropdown-item
                  command="registration"
                  icon="el-icon-tickets"
                  v-if="scope.row.type === 'activity'"
                >
                  已报名列表
                </el-dropdown-item>

                <el-dropdown-item
                  command="registrationList"
                  icon="el-icon-tickets"
                  v-if="scope.row.type === 'activity'"
                >
                  报名记录
                </el-dropdown-item>

                <el-dropdown-item
                  command="unpublish"
                  icon="el-icon-refresh"
                  v-hasPermi="['retirement:retirementArticlePublished:remove']"
                  divided
                >
                  撤销发布
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 文章预览对话框 -->
    <el-dialog  :visible.sync="previewOpen" width="50%" append-to-body>
      <div class="article-preview">
        <div class="article-header">
          <h2 class="article-title">{{ previewData.title }}</h2>
          <div class="article-meta">
            <span class="meta-item">所属部门：{{ previewData.deptName }}</span>
            <span class="meta-item">一级分类：{{ previewData.articleOneClassName }}</span>
            <span class="meta-item">二级分类：{{ previewData.articleTwoClassName }}</span>
            <span class="meta-item">文章类型：{{ getDictLabel(dict.type.article_type, previewData.type) }}</span>
            <span class="meta-item">创建时间：{{ previewData.createTime }}</span>
          </div>
        </div>
<!--        <div class="article-cover" v-if="previewData.image">
          <image-preview :src="previewData.image" :width="300" :height="200"/>
        </div>-->
        <div class="article-content" v-html="previewData.desc"></div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="previewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 收藏列表对话框 -->
    <el-dialog title="收藏列表" :visible.sync="collectOpen" width="70%" append-to-body>
      <el-form :model="collectQueryParams" ref="collectQueryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="姓名" prop="userName">
          <el-input
            v-model="collectQueryParams.userName"
            placeholder="请输入收藏人姓名"
            clearable
            @keyup.enter.native="handleCollectQuery"
          />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input
            v-model="collectQueryParams.phone"
            placeholder="请输入联系电话"
            clearable
            @keyup.enter.native="handleCollectQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleCollectQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetCollectQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="collectLoading" :data="collectList">
        <el-table-column label="姓名" align="center" prop="userName" />
        <el-table-column label="电话" align="center" prop="phone" />
        <el-table-column label="收藏时间" align="center" prop="createTime" />
      </el-table>

      <pagination
        v-show="collectTotal>0"
        :total="collectTotal"
        :page.sync="collectQueryParams.pageNum"
        :limit.sync="collectQueryParams.pageSize"
        @pagination="getCollectList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="collectOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 报名列表对话框 -->
    <el-dialog title="报名列表" :visible.sync="registrationOpen" width="70%" append-to-body>
      <el-form :model="registrationQueryParams" ref="registrationQueryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="姓名" prop="name">
          <el-input
            v-model="registrationQueryParams.name"
            placeholder="请输入报名人姓名"
            clearable
            @keyup.enter.native="handleRegistrationQuery"
          />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input
            v-model="registrationQueryParams.phone"
            placeholder="请输入报名人电话"
            clearable
            @keyup.enter.native="handleRegistrationQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleRegistrationQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetRegistrationQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="registrationLoading" :data="registrationList">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="电话" align="center" prop="phone" />
        <el-table-column label="报名时间" align="center" prop="date" />
      </el-table>

      <pagination
        v-show="registrationTotal>0"
        :total="registrationTotal"
        :page.sync="registrationQueryParams.pageNum"
        :limit.sync="registrationQueryParams.pageSize"
        @pagination="getRegistrationList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="registrationOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 报名记录对话框 -->
    <el-dialog title="报名记录" :visible.sync="registrationRecordOpen" width="70%" append-to-body>
      <el-form :model="registrationRecordQueryParams" ref="registrationRecordQueryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="报名状态" prop="status">
          <el-select v-model="registrationRecordQueryParams.status" placeholder="请选择报名状态" clearable>
            <el-option label="已报名" value="1" />
            <el-option label="取消报名" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleRegistrationRecordQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetRegistrationRecordQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="registrationRecordLoading" :data="registrationRecordList">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="电话" align="center" prop="phone" />
        <el-table-column label="报名状态" align="center" prop="status" >
          <template slot-scope="scope">
            <span>{{ scope.row.status === '1' ? '报名' : '取消报名' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作时间" align="center" prop="createTime" />
      </el-table>

      <pagination
        v-show="registrationRecordTotal>0"
        :total="registrationRecordTotal"
        :page.sync="registrationRecordQueryParams.pageNum"
        :limit.sync="registrationRecordQueryParams.pageSize"
        @pagination="getRegistrationRecordList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="registrationRecordOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 内容展示弹框 -->
    <el-dialog :title="contentDialog.title" :visible.sync="contentDialog.visible" width="60%" append-to-body>
      <div class="content-display">
        <pre>{{ contentDialog.content }}</pre>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="contentDialog.visible = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listRetirementArticlePublished, getRetirementArticlePublished, delRetirementArticlePublished, addRetirementArticlePublished, updateRetirementArticlePublished } from "@/api/retirement/retirementArticlePublished"
import { listRetirementMenu } from "@/api/retirement/retirementMenu"
import { listRetirementClassTwo } from "@/api/retirement/retirementClassTwo"
import { listRetirementCollect, listRetirementRecord } from "@/api/retirement/retirementCollect"
import { stickToTop, unpublish } from "@/api/retirement/retirementArticleReview"
import { deptTreeSelect } from "@/api/system/user"
import Treeselect from "@riophae/vue-treeselect"
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
import {listRetirementEnroll} from "@/api/retirement/retirementEnroll";

export default {
  name: "RetirementArticlePublished",
  components: { Treeselect },
  dicts: ['article_type', 'article_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 已发布文章表格数据
      retirementArticlePublishedList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示预览弹出层
      previewOpen: false,
      // 预览数据
      previewData: {},
      // 是否显示收藏列表弹出层
      collectOpen: false,
      // 收藏列表加载状态
      collectLoading: false,
      // 收藏列表数据
      collectList: [],
      // 收藏列表总数
      collectTotal: 0,
      // 当前文章ID（用于查询收藏列表）
      currentArticleId: null,
      // 部门树选项
      deptOptions: [],
      // 一级分类列表数据
      retirementMenuList: [],
      // 二级分类列表数据（用于搜索）
      retirementClassTwoList: [],
      // 内容展示弹框
      contentDialog: {
        visible: false,
        title: '',
        content: ''
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        desc: null,
        dept: null,
        articleOneClass: null,
        articleTwoClass: null,
        type: null,
        policyCode: null,
        image: null,
        isTop: null,
        location: null,
        source: null,
        status: null,
        reason: null,
        date: null,
        isDel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 收藏列表查询参数
      collectQueryParams: {
        pageNum: 1,
        pageSize: 10,
        articleId: null,
        userId: null,
        userName: null,
        phone: null,
      },
      // 是否显示报名列表弹出层
      registrationOpen: false,
      // 报名列表加载状态
      registrationLoading: false,
      // 报名列表数据
      registrationList: [],
      // 报名列表总数
      registrationTotal: 0,
      // 当前文章ID（用于查询报名列表）
      currentRegistrationArticleId: null,
      // 报名列表查询参数
      registrationQueryParams: {
        pageNum: 1,
        pageSize: 10,
        articleId: null,
        userId: null,
        name: null,
        phone: null,
        date: null,
      },
      // 是否显示报名记录弹出层
      registrationRecordOpen: false,
      // 报名记录加载状态
      registrationRecordLoading: false,
      // 报名记录数据
      registrationRecordList: [],
      // 报名记录总数
      registrationRecordTotal: 0,
      // 当前文章ID（用于查询报名记录）
      currentRegistrationRecordArticleId: null,
      // 报名记录查询参数
      registrationRecordQueryParams: {
        pageNum: 1,
        pageSize: 10,
        articleId: null,
        userId: null,
        status: null,
        date: null,
      }
    }
  },
  created() {
    this.getList()
    this.getDeptTree()
    this.getRetirementMenuList()
    this.getRetirementClassTwoList()
  },
  methods: {
    /** 查询已发布文章列表 */
    getList() {
      this.loading = true
      listRetirementArticlePublished(this.queryParams).then(response => {
        this.retirementArticlePublishedList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        desc: null,
        dept: null,
        articleOneClass: null,
        articleTwoClass: null,
        type: null,
        policyCode: null,
        image: null,
        isTop: null,
        location: null,
        source: null,
        status: null,
        reason: null,
        date: null,
        isDel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      // 重置时重新获取所有二级分类
      this.getRetirementClassTwoList()
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加已发布文章"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getRetirementArticlePublished(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改已发布文章"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRetirementArticlePublished(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addRetirementArticlePublished(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },

    /** 预览按钮操作 */
    handlePreview(row) {
      this.previewData = { ...row }
      this.previewOpen = true
    },

    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data
      })
    },

    /** 获取一级分类列表 */
    getRetirementMenuList() {
      listRetirementMenu({}).then(response => {
        this.retirementMenuList = response.data || []
      })
    },

    /** 获取二级分类列表（用于搜索） */
    getRetirementClassTwoList() {
      listRetirementClassTwo({}).then(response => {
        this.retirementClassTwoList = response.data || []
      })
    },

    /** 根据一级分类ID获取二级分类列表（用于搜索） */
    getQueryClassTwoList(levelOneId) {
      if (!levelOneId) {
        this.retirementClassTwoList = []
        return
      }
      listRetirementClassTwo({ levelOneId: levelOneId }).then(response => {
        this.retirementClassTwoList = response.data || []
      })
    },

    /** 搜索表单一级分类变化处理 */
    handleOneClassChange(value) {
      // 清空二级分类选择
      this.queryParams.articleTwoClass = null
      // 根据一级分类ID获取对应的二级分类
      this.getQueryClassTwoList(value)
    },
    /** 搜索表单文章类型变化处理 */
    handleQueryTypeChange(value) {
      // 这里可以添加搜索表单文章类型变化的逻辑
      console.log('搜索表单文章类型变化:', value)
    },

    /** 获取字典标签 */
    getDictLabel(dictOptions, value) {
      if (!dictOptions || !value) return ''
      const option = dictOptions.find(item => item.value === value)
      return option ? option.label : ''
    },

    /** 收藏列表按钮操作 */
    handleCollectList(row) {
      this.currentArticleId = row.id
      this.collectQueryParams.articleId = row.id
      this.collectQueryParams.pageNum = 1
      this.collectOpen = true
      this.getCollectList()
    },

    /** 查询收藏列表 */
    getCollectList() {
      this.collectLoading = true
      listRetirementEnroll(this.collectQueryParams).then(response => {
        this.collectList = response.rows
        this.collectTotal = response.total
        this.collectLoading = false
      })
    },

    /** 收藏列表搜索按钮操作 */
    handleCollectQuery() {
      this.collectQueryParams.pageNum = 1
      this.getCollectList()
    },

    /** 收藏列表重置按钮操作 */
    resetCollectQuery() {
      this.resetForm("collectQueryForm")
      this.collectQueryParams.articleId = this.currentArticleId
      this.handleCollectQuery()
    },

    /** 报名列表按钮操作 */
    handleRegistrationList(row) {
      this.currentRegistrationArticleId = row.id
      this.registrationQueryParams.articleId = row.id
      this.registrationQueryParams.pageNum = 1
      this.registrationOpen = true
      this.getRegistrationList()
    },

    /** 查询报名列表 */
    getRegistrationList() {
      this.registrationLoading = true
      listRetirementCollect(this.registrationQueryParams).then(response => {
        this.registrationList = response.rows
        this.registrationTotal = response.total
        this.registrationLoading = false
      })
    },

    /** 报名列表搜索按钮操作 */
    handleRegistrationQuery() {
      this.registrationQueryParams.pageNum = 1
      this.getRegistrationList()
    },

    /** 报名列表重置按钮操作 */
    resetRegistrationQuery() {
      this.resetForm("registrationQueryForm")
      this.registrationQueryParams.articleId = this.currentRegistrationArticleId
      this.handleRegistrationQuery()
    },

    /** 报名记录按钮操作 */
    handleRegistrationRecordList(row) {
      this.currentRegistrationRecordArticleId = row.id
      this.registrationRecordQueryParams.articleId = row.id
      this.registrationRecordQueryParams.pageNum = 1
      this.registrationRecordOpen = true
      this.getRegistrationRecordList()
    },

    /** 查询报名记录 */
    getRegistrationRecordList() {
      this.registrationRecordLoading = true
      listRetirementRecord(this.registrationRecordQueryParams).then(response => {
        this.registrationRecordList = response.rows
        this.registrationRecordTotal = response.total
        this.registrationRecordLoading = false
      })
    },

    /** 报名记录搜索按钮操作 */
    handleRegistrationRecordQuery() {
      this.registrationRecordQueryParams.pageNum = 1
      this.getRegistrationRecordList()
    },

    /** 报名记录重置按钮操作 */
    resetRegistrationRecordQuery() {
      this.resetForm("registrationRecordQueryForm")
      this.registrationRecordQueryParams.articleId = this.currentRegistrationRecordArticleId
      this.handleRegistrationRecordQuery()
    },

    /** 置顶按钮操作 */
    handleStickToTop(row) {
      const isTop = row.isTop === '1' ? '0' : '1'
      const actionText = row.isTop === '1' ? '取消置顶' : '置顶'

      this.$modal.confirm('确定' + actionText + '文章吗？').then(() => {
        const data = {
          id: row.id,
          isTop: isTop
        }
        stickToTop(data).then(response => {
          this.$modal.msgSuccess(actionText + '成功')
          this.getList()
        })
      }).catch(() => {})
    },

    /** 撤销发布按钮操作 */
    handleUnpublish(row) {
      this.$modal.confirm('确认撤销发布吗？').then(() => {
        const data = {
          id: row.id
        }
        unpublish(data).then(response => {
          this.$modal.msgSuccess('撤销发布成功')
          this.getList()
        })
      }).catch(() => {})
    },

    /** 处理操作下拉菜单命令 */
    handleActionCommand(command, row) {
      switch (command) {
        case 'collect':
          this.handleCollectList(row)
          break
        case 'stick':
          this.handleStickToTop(row)
          break
        case 'registration':
          this.handleRegistrationList(row)
          break
        case 'registrationList':
          this.handleRegistrationRecordList(row)
          break
        case 'unpublish':
          this.handleUnpublish(row)
          break
        default:
          break
      }
    },
    // 显示内容弹框
    showContentDialog(title, content) {
      this.contentDialog.title = title
      this.contentDialog.content = content
      this.contentDialog.visible = true
    },
  }
}
</script>

<style scoped>
/* 操作列样式优化 */
.action-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.action-btn {
  margin: 0 !important;
  padding: 5px 8px !important;
  font-size: 12px !important;
  border-radius: 4px !important;
  transition: all 0.3s ease;
}

.primary-btn {
  background-color: #409eff !important;
  border-color: #409eff !important;
  color: #fff !important;
}

.primary-btn:hover {
  background-color: #66b1ff !important;
  border-color: #66b1ff !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
}

.dropdown-btn {
  color: #606266 !important;
  border: 1px solid #dcdfe6 !important;
  background-color: #fff !important;
}

.dropdown-btn:hover {
  color: #409eff !important;
  border-color: #c6e2ff !important;
  background-color: #ecf5ff !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 下拉菜单样式优化 */
.action-buttons >>> .el-dropdown-menu {
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border: none;
  padding: 8px 0;
}

.action-buttons >>> .el-dropdown-menu__item {
  padding: 8px 16px;
  font-size: 13px;
  transition: all 0.2s ease;
}

.action-buttons >>> .el-dropdown-menu__item:hover {
  background-color: #f5f7fa;
  color: #409eff;
}

.action-buttons >>> .el-dropdown-menu__item.is-divided {
  border-top: 1px solid #e4e7ed;
  margin-top: 4px;
  padding-top: 12px;
}

/* 表格操作列宽度优化 */
.el-table .el-table__body-wrapper .el-table__row .el-table__cell:last-child {
  padding: 8px !important;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .action-buttons {
    flex-direction: column;
    gap: 4px;
  }

  .action-btn {
    width: 100%;
    text-align: center;
  }
}

.article-preview {
  max-height: 70vh;
  overflow-y: auto;
}

.article-header {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e6e6e6;
}

.article-title {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin: 0 0 15px 0;
  line-height: 1.4;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  font-size: 14px;
  color: #666;
}

.meta-item {
  white-space: nowrap;
}

.article-cover {
  text-align: center;
  margin: 20px 0;
}

.article-content {
  margin-top: 20px;
  line-height: 1.8;
  font-size: 16px;
  color: #333;
}

.article-content >>> img {
  max-width: 100%;
  height: auto;
  margin: 10px 0;
}

.article-content >>> p {
  margin: 10px 0;
}

.article-content >>> h1,
.article-content >>> h2,
.article-content >>> h3,
.article-content >>> h4,
.article-content >>> h5,
.article-content >>> h6 {
  margin: 20px 0 10px 0;
  font-weight: bold;
}

.article-content >>> ul,
.article-content >>> ol {
  margin: 10px 0;
  padding-left: 30px;
}

.article-content >>> blockquote {
  margin: 15px 0;
  padding: 10px 15px;
  background-color: #f5f5f5;
  border-left: 4px solid #409eff;
}
.text-truncate {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  color: #409EFF;
}

.text-truncate:hover {
  color: #66b1ff;
}

.content-display {
  max-height: 500px;
  overflow-y: auto;
  padding: 10px;
  background-color: #f5f5f5;
  border-radius: 4px;
}

.content-display pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
  font-family: inherit;
  line-height: 1.5;
}
</style>
